import Vue from "vue";
import Vuex from "vuex";
import http from "@/utils/request";
import { getToken } from "@/utils/authToken";
Vue.use(Vuex);

// 创建一个vuex状态管理器
var store = new Vuex.Store({
    state:{ //调用方案一：this.$store.state.siteTitle
        siteTitle:"健景平台中心，愿您身体康健", //站点名称
        patientId:"",
        patientIdCard:"",
        patientSex:"",
        patientName:"",    
        patientPwd:"",
        patientMoney:0,
        patientPhone:""
    },
    getters:{
        getSiteTitle(state){  //调用方案二：this.$store.getters.getSiteTitle 
            return state.siteTitle
        }
    },
    mutations:{
        setSiteTitle(state,val){
            state.siteTitle = val
        },
        setPatientId(state,val){
            state.patientId = val
        },
        setPatientIdCard(state,val){
            state.patientIdCard = val
        },
        setPatientSex(state,val){
            state.patientSex = val
        },
        setPatientName(state,val){
            state.patientName = val
        },
        setPatientPwd(state,val){
            state.patientPwd = val
        },
        setPatientMoney(state,val){
            state.patientMoney = val
        },
        setPatientPhone(state,val){
            state.patientPhone = val
        }
        

    },
    actions:{
        setPatient(store,val){
            console.log("111",val)
            store.commit("setPatient",val)
        },
        async getPatientInfo(store){
            return await http.get(
                "/patient/getPatientInfo",
                {
                    params:{
                        token:getToken()
                    }
                }
            ).then(res =>{
                console.log("信息",res)
                if(res != false){
                    // 等会这就去修改state里面的adminId等信息
                    store.commit("setPatientId",res.data.patientInfo.patientId)
                    store.commit("setPatientIdCard",res.data.patientInfo.patientIdCard)
                    store.commit("setPatientSex",res.data.patientInfo.patientSex)
                    store.commit("setPatientName",res.data.patientInfo.patientName)
                    store.commit("setPatientPwd",res.data.patientInfo.patientPwd)
                    store.commit("setPatientMoney",res.data.patientInfo.patientMoney)
                    store.commit("setPatientPhone",res.data.patientInfo.patientPhone)
                    return true
                }else{
                    return false
                }
                
            })
        }
    }
})
export default store